<form class="layui-form" id="search-form">
    <div style="min-height: 38px;margin-top: 5px;">
        <div class="layui-inline">
            <label class="layui-form-label">日期范围</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input time" id="date" placeholder="" style="width:200px;">
            </div>
        </div>
        <!--        <button type="button" class="layui-btn layui-btn-primary search"><i class="layui-icon">&#xe615;</i></button>-->
    </div>
</form>
<br>

<table class="layui-table">
    <colgroup>
        <col width="20%">
        <col width="">
        <col>
    </colgroup>
    <thead>
    <tr>
        <th>栏目</th>
        <th>下载</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>配音</td>
        <td>
            <!--            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"-->
            <!--               onclick="jump('audio',1)">观看数(PV)</a>-->
            <!--            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"-->
            <!--               onclick="jump('audio',2)">观看数(UV)</a>-->
            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"
               onclick="jump('audio',4)">产出比</a>
            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"
               onclick="jump('audio',3)">分享数</a>
            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"
               onclick="jump('audio',6)">PV/UV</a>
            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"
               onclick="jump('audio',5)">配音条数</a>
        </td>
    </tr>
    <tr>
        <td>视频</td>
        <td>
            <!--            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"-->
            <!--               onclick="jump('video',1)">观看数(PV)</a>-->
            <!--            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"-->
            <!--               onclick="jump('video',2)">观看数(UV)</a>-->
            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"
               onclick="jump('video',3)">点赞数</a>
            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"
               onclick="jump('video',4)">分享数</a>
            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"
               onclick="jump('video',6)">PV/UV</a>
        </td>
    </tr>
    <tr>
        <td>UGC配音</td>
        <td>
            <!--            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"-->
            <!--               onclick="jump('ugc',1)">观看数(PV)</a>-->
            <!--            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"-->
            <!--               onclick="jump('ugc',2)">观看数(UV)</a>-->
            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"
               onclick="jump('ugc',3)">点赞数</a>
            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"
               onclick="jump('ugc',4)">分享数</a>
            <a class="layui-btn layui-btn-xs layui-btn-normal" target="_blank"
               onclick="jump('ugc',6)">PV/UV</a>
        </td>
    </tr>
    </tbody>
</table>

<script src="<?= SITE_BASE_URL ?>/assets/js/echarts.min.js"></script>
<script>
    $(function () {
        //日期选择
        var laydate = layui.laydate;

        var eDate = new Date().Format("yyyy-MM-dd");
        var date = new Date();
        date.setDate(date.getDate()-6);
        var sDate = date.Format("yyyy-MM-dd");

        laydate.render({
            elem: '#date'
            , max: "eDate"
            , range: '~'
            , value: sDate + " ~ " + eDate
        });
    });

    function jump(uri, type) {
        var date = $('#date').val();
        if (date == null || date === "" || date === undefined) {
            layui.layer.msg("请选择日期");
            return;
        }
        var start_date = trim(date.split('~')[0]);
        var end_date = trim(date.split('~')[1]);

        var days = daysBetween(start_date, end_date);
        if (days > 7) {
            layui.layer.msg("日期最多选择七天");
            return;
        }

        var jump_url = "<?=base_url('statics/down_excel/')?>" + uri
            + "?type=" + type
            + "&start_date=" + start_date
            + "&end_date=" + end_date;

        window.open(jump_url);

    }

    function daysBetween(sDate1, sDate2) {
        var time1 = Date.parse(new Date(sDate1));
        var time2 = Date.parse(new Date(sDate2));
        var nDays = Math.abs(parseInt((time2 - time1) / 1000 / 3600 / 24)) + 1;
        return nDays;
    }

    function trim(str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }

    Date.prototype.Format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

</script>
